import { defHttp } from '/@/utils/http/axios';
import {
  FixResidentListGetResultModel,
  FixResidentModel,
  FixResidentPageListGetResultModel,
  FixResidentParams,
  FixResidentPageSearchParams,
  FixResidentListSearchParams,
  UpdateFixResidentParams,
  FixResidentIDType,
} from '/@/api/opms/model/FixResidentModel';

import { UploadFileParams } from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting';
import { UploadApiResult } from '../sys/model/uploadModel';

// 居民管理接口
export enum Api {
  PublicApi = '/opms/fix-resident',
  ListApi = `/opms/fix-resident/list`,
  PageApi = `/opms/fix-resident/page`,
  BatchApi = `/opms/fix-resident/batch`,
  ExportApi = `/opms/fix-resident/export`,
  ExportRewriteApi = `/opms/fix-resident/exportExcel`,
  ImportApi = `/opms/fix-resident/import`,
  ImportExcelApi = `/opms/fix-resident/importExcel`,
  GetFieldsApi = `/opms/fix-resident/getFields`,
}

/**
 * @description:  获取列表
 * @param params
 * @returns
 */
export const getFixResidentList = (params?: FixResidentListSearchParams) =>
  defHttp.get<FixResidentListGetResultModel>({ url: Api.ListApi, params });

export const getFixResidentFieldsList = () => defHttp.get({ url: Api.GetFieldsApi });

/**
 * @description:  分页获取列表
 * @param params
 * @returns
 */
export const getFixResidentPage = (params: FixResidentPageSearchParams) =>
  defHttp.get<FixResidentPageListGetResultModel>({ url: Api.PageApi, params });

/**
 * @description:  根据id获取
 * @param id
 * @returns
 */
export const getFixResident = (id: FixResidentIDType) =>
  defHttp.get<FixResidentModel>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  创建
 * @param params
 * @returns
 */
export const createFixResident = (params: FixResidentParams) =>
  defHttp.post<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  更新
 * @param params
 * @returns
 */
export const updateFixResident = (params: UpdateFixResidentParams) =>
  defHttp.put<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  物理删除
 * @param id
 * @returns
 */
export const deleteFixResident = (id: FixResidentIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  物理批量删除
 * @param ids
 * @returns
 */
export const deleteFixResidentBatch = (ids: FixResidentIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  逻辑删除
 * @param ids
 * @returns
 */
export const logicDeleteFixResident = (id: FixResidentIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  逻辑批量删除
 * @param ids
 * @returns
 */
export const logicDeleteFixResidentBatch = (ids: FixResidentIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  导出文件
 * @param ids
 * @returns
 */
export const exportFixResidentListFile = (ids: FixResidentIDType[]) =>
  defHttp.post<boolean>({ url: Api.ExportApi, params: { ids } });

export const exportRewriteExcel = (params?) =>
  defHttp.get(
    { url: Api.ExportRewriteApi, params, responseType: 'blob' },
    { isReturnNativeResponse: true },
  );

/**
 * @description:  导入文件
 * @param ids
 * @returns
 */
export const importFixResidentListFile = (
  params: UploadFileParams,
  onUploadProgress?: (progressEvent: ProgressEvent) => void,
) =>
  defHttp.uploadFile<UploadApiResult>(
    {
      url: useGlobSetting().apiUrl + Api.ImportApi,
      onUploadProgress,
    },
    params,
  );

export const importBomInventoryList = (params?) =>
  defHttp.post({ url: Api.ImportExcelApi, params });
